#ifndef UDPRECIVE_H
#define UDPRECIVE_H

#include <QtNetwork/QUdpSocket>
#include "qthread.h"
#include "qdebug.h"
#include "mainwindow.h"

class UdpReciver : public QObject
{
    Q_OBJECT
public:
    UdpReciver(int port, QObject *parent = NULL);
    ~UdpReciver();
    // 设置客户端ip和port
    void init_port(QString tmphost, int tmport);
    // 设置端口
    void init_port(int tmport);
    // 客户端ip
    QString strclient_address = "0.0.0.0";
    // 客户端数据
    QByteArray m_data;

signals:
    void deliverInfo(QByteArray info, QString clientip);

public slots:
    // 接收udp数据
    void readDatagrams();

private:
    QUdpSocket *m_udpSocket;
    QString m_localhost;
    int m_port;
    QThread *m_thread;
};

#endif // UDPRECIVE_H
